import Flutter
import UIKit

public class SwiftPluginGetVersionPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "plugin_get_version", binaryMessenger: registrar.messenger())
    let instance = SwiftPluginGetVersionPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    
    switch call.method {
    case "getAppVersionName":
        let infoDictionary = Bundle.main.infoDictionary!
        let appversion = infoDictionary["CFBundleShortVersionString"] as! String   //获取app的版本号
        result(appversion)
    case "getAppVersionCode":
        let infoDictionary = Bundle.main.infoDictionary!
        let appversion = infoDictionary["CFBundleVersion"] as! String   //获取app的版本号
        result(appversion)
    default:
        result("iOS " + UIDevice.current.systemVersion)
    }
    
  }
}
